package com.sxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sxt.common.DataGridView;


import com.sxt.domain.Goods;
import com.sxt.domain.GoodsType;

import com.sxt.mapper.GoodsMapper;


import com.sxt.service.GoodsService;

import com.sxt.service.GoodsTypeService;
import com.sxt.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsVoServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Autowired
    private GoodsTypeService goodsTypeService;

    @Override
    public DataGridView queryAllGoods(GoodsVo goodsVo) {
        QueryWrapper<Goods> qw=new QueryWrapper<>();
        qw.eq(goodsVo.getTypeId()!=null,"typeId",goodsVo.getTypeId());
        qw.ge(goodsVo.getCreateTime()!=null,"createTime",goodsVo.getCreateTime());
        qw.le(goodsVo.getUpdateTime()!=null,"updateTime",goodsVo.getUpdateTime());
        qw.orderByDesc("createTime");

        IPage<Goods> page=new Page<>(goodsVo.getPage(),goodsVo.getLimit());


        this.goodsMapper.selectPage(page,qw);
        List<Goods> records = page.getRecords();
        for (Goods record : records) {
            if(record.getTypeId()!=null){
                GoodsType goodsType = goodsTypeService.getById(record.getTypeId());
                record.setGoodsName(goodsType.getTypeName());//.setTypename(billType.getName());
            }
        }
        return new DataGridView(page.getTotal(), records);
    }
}
